package org.spring.demo.config;

import org.spring.demo.wx.WXPay;
import org.spring.demo.wx.WXPayConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeanConfig {

	@Value("${wx.app.appId}")  
	private String appId;
	@Value("${wx.app.mchid}")  
	private String mchid;
	@Value("${wx.app.key}")  
	private String key;
	
	@Bean(name = "appConfig")
	public WXPayConfig wxPayConfig(@Value("${wx.app.key}") String key,
            @Value("${wx.app.appId}") String appId, @Value("${wx.app.mchid}") String mchId) throws Exception{
		WXPayConfig appWXPayConfig = new WXPayConfig();
		appWXPayConfig.setAppId(appId);
		appWXPayConfig.setMchid(mchId);
		appWXPayConfig.setKey(key);
		return appWXPayConfig;
		
	}
	
	@Bean(name = "appPayCon")
	public WXPay wxPay(@Autowired WXPayConfig appConfig) throws Exception{
		WXPay appWXPay = new WXPay(appConfig);
		return appWXPay;
		
	}
}
